package com.freewater.springboot.demo.aop.advice.afterreturn;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class PersonAspect {

    @Pointcut("execution(* com.freewater.springboot.demo.aop.advice.afterreturn.PersonService.*(..))")
    public void allMethod() {

    }

    // 注意，returning属性对应的person为Person类型，因此也限定了只能拦截返回值类型为Person类的场景
    @AfterReturning(value = "allMethod() && args(name,age)", returning = "person", argNames = "joinPoint,age,name,person")
    public void beforeAdvice(JoinPoint joinPoint, int age, String name, Person person) {
        System.out.println("params age: " + age);
        System.out.println("params name: " + name);
        System.out.println("return person: " + person);
    }

}
